<?php
/*
Overmundo, cultura de todo o Brasil
Desenvolvido pela Tecnopop para o Núcleo de Idéias Movimento
Copyright (C) 2006  Núcleo de Idéias Movimento

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

// CONFIG GERAL //
if (defined('ABSPATH')) {
    require_once( ABSPATH . 'ov_config.php');
} else {
    require_once('../ov_config.php'); // tem que ser relativo!
}

$nivelPagina = "desconhecido";
$secaoAtual = "estaticas";
//Itens BreadCrumb

include('../lib/checa_login.php');

require_once('../lib/class.site.php');
require_once('../lib/class.overmundo.php');
require_once('../lib/class.conecta.php');

// INIT //
require_once(ABSPATH . SHARED . '/smarty_init.php');
require_once(ABSPATH . SHARED . '/db_init.php');

session_start();
//$nomeSessao = session_name();
//if ((!$$nomeSessao) || ($usuarioValido == "")) {
if (!isset($minhaConexao))  {
	$minhaConexao = new Conecta();
}
if (!isset($meuSite)) {
	$meuSite = new Overmundo();
}

if (!isset($meuSite->linkid)) { 
	$meuSite->linkid = $minhaConexao->linkid;
}


$universoTags = 120;
$resTags = $meuSite->OvermundoRankTags($universoTags);

if ($x = @mysql_num_rows($resTags)) {
	extraiHits($resTags, $arrResultadoTags, $universoTags);
	$hitsPublicados = 1;
}

usort($arrResultadoTags, "cmpAlfabetica");

function extraiHits($result, 	&$arrResultado, $universoTags) {
	//global $arrResultadoPublicadas;
	$prim = 1;
    $ccTags = 0;
    while ($row = mysql_fetch_array($result)) {
	    unset($esseHit);
	    $esseHit = Array();
	    $ccTags++;
	    while (list($campo, $valor) = each($row)) {
		    if (!is_numeric($campo)) {
			    if (substr($campo, 0, 6) == "titulo") {
				    $esseHit["tag"] = $valor;
			    } else if (($str = substr($campo, 0, 4)) == "hits") {
				    $esseHit["hits"] = $valor;
				    
				    if ($ccTags < (($universoTags / 8) * 1)) {
					    $esseHit["classe"] = "tag-8";
				    } else if ($ccTags < (($universoTags / 8) * 2)) {
					    $esseHit["classe"] = "tag-7";
				    } else if ($ccTags < (($universoTags / 8) * 3)) {
					    $esseHit["classe"] = "tag-6";
				    } else if ($ccTags < (($universoTags / 8) * 4)) {
					    $esseHit["classe"] = "tag-5";
				    } else if ($ccTags < (($universoTags / 8) * 5)) {
					    $esseHit["classe"] = "tag-4";
				    } else if ($ccTags < (($universoTags / 8) * 6)) {
					    $esseHit["classe"] = "tag-3";
				    } else if ($ccTags < (($universoTags / 8) * 7)) {
					    $esseHit["classe"] = "tag-2";
				    } else {
					    $esseHit["classe"] = "tag-1";
				    } 
//	    echo "ccTags $ccTags (" . $esseHit["tag"] . ") " . $esseHit["hits"] . " -  <BR>";
				    
			    } 
			    
		    }
		    
		    
		}
	    $arrResultado[] = $esseHit;
//	    echo "ACHEI " . $esseHit["tag"] . "(" . $esseHit["hits"] . ") -  <BR>";

	}
//	    $esseHit["relevancia"] = $somaRelevancia;

}

function cmpAlfabetica($a, $b)
{
	if ($a["tag"] < $b["tag"]) {
		return (-1);
	} else if ($a["tag"] == $b["tag"]) {
		return (0);
	} else {
		return (1);
	}
}

$ptrArray = 0;
while ($ptrArray < count($arrResultadoTags)) {
	$tag = $arrResultadoTags[$ptrArray++];
    $smarty->append('tags', $tag);
}

$smarty->display('templates/nuvem_tags.html');

?>